

$(function(f) {
var x = 60;
var v = 0;
var b = document.getElementById("bgScreen");
var u = f(document).width();
var o = f(document).height();
var q = Processing(b);
var l = 0;
var k = 0;
var t = 0;
var s = 0;
var g = 0;
var e = 0;
var a;
var c;
var d = 0;
var h = [];
h[0] = 0;
for(m = 1; m < 30; m++) {
h[m] = 8000 * m;
}
var w = false;
components = [];
var n = [];
for(v = 0; v < x; v++) {
n[v] = {
  x: Math.random() * u,
  y: Math.random() * o,
  toX: u / 2,
  toY: o,
  color: 0,
  angle: Math.random() * Math.PI * 2,
  size: 0,
  toSize: Math.random() * 5 + 1,
  r: 0,
  g: 0,
  b: 0,
  toR: Math.random() * 115,
  toG: 0,
  toB: Math.random() * 115,
  flightMode: 0
};
n[v].toX = n[v].x;
n[v].toY = n[v].y;
n[v].speedX = 0;
n[v].speedY = 0;
}
var y = [function() {
for(v = 0; v < n.length; v++) {
  var i = n[v];
  i.speedX = Math.cos(i.angle) * Math.random() * 3;
  i.speedY = Math.sin(i.angle) * Math.random() * 3;
}
}];
var r = function j() {
return {
  framecount: 0,
  update: function() {
    t = t + (g - t) / 100;
    s = s + (e - s) / 100;
    for(v = 0; v < n.length; v++) {
      n[v].x = n[v].x + (n[v].toX - n[v].x) / 100;
      n[v].y = n[v].y + (n[v].toY - n[v].y) / 100;
      n[v].size = n[v].size + (n[v].toSize - n[v].size) / 10;
      n[v].r = n[v].r + (n[v].toR - n[v].r) / 10;
      n[v].g = n[v].g + (n[v].toG - n[v].g) / 10;
      n[v].b = n[v].b + (n[v].toB - n[v].b) / 10;
    }
    for(v = 0; v < n.length; v++) {
      var A = Math.abs(n[v].toX - l) * Math.abs(n[v].toX - l);
      var i = Math.abs(n[v].toY - k) * Math.abs(n[v].toY - k);
      var D = Math.sqrt(A + i);
      if(D < 500) {
        if(n[v].flightMode === 0) {
          var C = Math.atan2(n[v].y - k, n[v].x - l) * 180 / Math.PI + Math.random() * 180 - 90;
          n[v].degree = C;
          n[v].degreeSpeed = Math.random() * 1 + 0.5;
          n[v].frame = 0;
        }
        n[v].flightMode = 1;
      } else {
        n[v].flightMode = 0;
      }
      if(n[v].flightMode === 0) {
        n[v].toX += n[v].speedX;
        n[v].toY += n[v].speedY;
        if(n[v].x < 0) {
          n[v].x = u;
          n[v].toX = u;
        }
        if(n[v].x > u) {
          n[v].x = 0;
          n[v].toX = 0;
        }
        if(n[v].y < 0) {
          n[v].y = o;
          n[v].toY = o;
        }
        if(n[v].y > o) {
          n[v].y = 0;
          n[v].toY = 0;
        }
      }
      if(n[v].flightMode === 1) {
        n[v].toX = l + Math.cos((n[v].degree + n[v].frame) % 360 * Math.PI / 180) * D;
        n[v].toY = k + Math.sin((n[v].degree + n[v].frame) % 360 * Math.PI / 180) * D;
        n[v].frame += n[v].degreeSpeed;
        n[v].degreeSpeed += 0.05;
      }
      n[v].toX += Math.floor(t * n[v].size / 30);
      n[v].toY += Math.floor(s * n[v].size / 30);
    }
    var B = Math.floor(Math.random() * n.length);
    var z = Math.floor(Math.random() * n.length);
    if(n[B].flightMode != 2) {
      n[B].size = Math.random() * 20;
    }
    if(n[z].flightMode != 2) {
      n[z].size = Math.random() * 20;
    }
    this.framecount++;
    if(d >= h.length) {
      a = new Date();
      d = 0;
    }
    c = new Date();
    if(c.getTime() - a.getTime() >= h[d]) {
      d++;
      t = -Math.random() * 100 - 50;
      s = -Math.random() * 600 - 300;
      var p = Math.floor(Math.random() * y.length);
      y[p]();
    }
  },
  draw: function() {
    for(v = 0; v < n.length; v++) {
      q.fill(Math.floor(n[v].r), Math.floor(n[v].g), Math.floor(n[v].b));
      q.ellipse(n[v].x, n[v].y, n[v].size, n[v].size);
    }
  }
};
};
components.push(new r());
q.setup = function() {
q.size(u, o);
q.noStroke();
q.frameRate(60);
q.fill(0, 0, 0);
a = new Date();
};
q.mouseMoved = function() {
l = q.mouseX;
k = q.mouseY;
};
q.draw = function() {
if(w) {
  for(var z = 0; z < components.length; z++) {
    components[z].update();
  }
  q.background(245);
  for(var p = 0; p < components.length; p++) {
    components[p].draw();
  }
}
};
q.init();
w = true;
f(window).resize(function() {
u = f(document).width();
o = f(document).height();
q.size(u, o);
});
});